﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tdb.YY.DAL;
using Tdb.YY.DTO;
using Tdb.YY.DTO.YY;

namespace Tdb.YY.BLL
{
    /// <summary>
    /// YY1 逻辑
    /// </summary>
    public class YY1BLL : BaseBLL
    {
        #region 公开方法

        /// <summary>
        /// 查询YY1类型
        /// </summary>
        /// <returns></returns>
        public async Task<List<YYCTypeListInfo>> QueryCTypeAsync()
        {
            var lstCType = await YY1DAL.Inst.QueryCTypeAsync();

            var list = new List<YYCTypeListInfo>();
            foreach (var cType in lstCType)
            {
                list.Add(new YYCTypeListInfo() { CType = cType });
            }

            return list;
        }

        /// <summary>
        /// 查询YY1列表
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        public async Task<PageList<YYListInfo>> QueryListAsync(YYListReq req)
        {
            var lstModel = await YY1DAL.Inst.QueryListAsync(req);

            var list = new List<YYListInfo>();
            foreach (var model in lstModel)
            {
                list.Add(new YYListInfo() { ID = model.ID, Title = model.Title });
            }

            return new PageList<YYListInfo>(list, lstModel.TotalRecord);
        }

        /// <summary>
        /// 过滤YY1列表
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        public async Task<PageList<YYListInfo>> FilterListAsync(YYFilterListReq req)
        {
            var lstModel = await YY1DAL.Inst.FilterListAsync(req);

            var list = new List<YYListInfo>();
            foreach (var model in lstModel)
            {
                var item = new YYListInfo();
                list.Add(item);

                item.ID = model.ID;
                item.Title = model.Title;
            }

            return new PageList<YYListInfo>(list, lstModel.TotalRecord);
        }

        /// <summary>
        /// 查询YY1信息
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public async Task<YYInfo> GetByIDAsync(int id)
        {
            var model = await YY1DAL.Inst.GetByIDAsync(id);
            if (model == null)
            {
                return null;
            }

            var item = new YYInfo();
            item.ID = model.ID;
            //item.Title = Helper.EncryptHelper.EncryptAES(model.Title);
            //item.Content = Helper.EncryptHelper.EncryptAES(model.Content);
            item.Title = model.Title;
            item.Content = model.Content;
            item.Right = model.Right;

            return item;
        }

        /// <summary>
        /// 查询异常记录url列表
        /// </summary>
        /// <returns></returns>
        public async Task<List<string>> QueryErrorUrlAsync()
        {
            var list = await YY1DAL.Inst.QueryErrorUrlAsync();
            list = list.Distinct().ToList();
            return list;
        }

        /// <summary>
        /// 删除异常记录
        /// </summary>
        /// <returns></returns>
        public async Task<int> DeleteErrorInfoAsync()
        {
            var count = await YY1DAL.Inst.DeleteErrorInfoAsync();
            return count;
        }

        /// <summary>
        /// 标题重复的记录去重
        /// </summary>
        /// <returns></returns>
        public async Task<int> DistincTitleAsync()
        {
            var count = await YY1DAL.Inst.DistincTitleAsync();
            return count;
        }

        /// <summary>
        /// 修改权重
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        public async Task ModifyRightAsync(YYModifyRightReq req)
        {
            await YY1DAL.Inst.ModifyRightAsync(req);
        }

        #endregion
    }
}
